﻿
/// <reference path="vswd-ext_2.2.js" />

/********************loginwindow.js*********************************

*Create Date: 2009-12-23
*Description : this js file use ext js to create AJAX query window 
*********************************************************************/
function alarmWindow() {

	var day = new Date();
	var today = day.getFullYear() + '-' + padLeft((day.getMonth() + 1).toString(), "0", 2) + '-' + padLeft(day.getDate().toString(), "0", 2);
	var yyday = addDays(day, -1);
	var yestoday = yyday.getFullYear() + '-' + padLeft((yyday.getMonth() + 1).toString(), "0", 2) + '-' + padLeft(yyday.getDate().toString(), "0", 2);
	var pagesize = 15;

	var alarmData = [
		['2', _AlarmResource_ButtonB_Pressed_Input2_Active],
		['50', _AlarmResource_ButtonB_Released_Input2_InActive],
		['3', _AlarmResource_ButtonC_Pressed_Input3_Active],
		['51', _AlarmResource_ButtonC_Released_Input3_InActive],
		['21', _AlarmResource_EnterGPSBlindAlarm],
		['22', _AlarmResource_ExitGPSBlindAlarm],
		['80', _AlarmResource_External_power_cut_alarm],
		['18', _AlarmResource_MovementAlarm],
		['19', _AlarmResource_GeoFenceAlarm],
		['4', _AlarmResource_Input4_Active],
		['52', _AlarmResource_Input4_InActive],
		['5', _AlarmResource_Input5_Active],
		['53', _AlarmResource_Input5_InActive],
		['16', _AlarmResource_LowBattery],
		['17', _AlarmResource_OverSpeed],
		['1', _AlarmResource_SOSButton_Pressed_Input1_Active],
		['49', _AlarmResource_SOSButton_Released_Input1_InActive],
		['20', _AlarmResource_TurnOnAlarm],
		['82', _AlarmResource_Veer_report],
		['105', _AlarmResource_LowExternalPower],
		['112', _AlarmResource_EnterGeofence],
		['113', _AlarmResource_ExitGeofence],
		['114', _AlarmResource_ExternalPowerOn],
		['115', _AlarmResource_ExternalPowerOff],
		['116', _AlarmResource_EnterSleep],
		['117', _AlarmResource_ExitSleep],
		['118', _AlarmResource_GPSAntennaCut],
		//['119', _AlarmResource_Impact],
		//['120', _AlarmResource_HeartbeatReport],
		//['121', _AlarmResource_DistanceIntervalReport],
		//['122', _AlarmResource_CurrentLocationReport],
		//['123', _AlarmResource_TimeIntervalReport],
		['124', _AlarmResource_TowAlarm],
		//  ['125', _AlarmResource_RFID],
		['40', _AlarmResource_PowerOff],
		['41', _AlarmResource_Stay],
		['42', _AlarmResource_Moving]
		]

	var pgeofencefields, pgeofencestore;

	if (typeof (showWDDefine) != 'undefined') {
		if (showWDDefine) {
			alarmData.push(['46', _AlarmResource_FuelAlarm]);
		}
	}

	if (showPolygonFence) {
		pgeofencefields = ["polygon_geofence_id", "points", "create_account", "create_type", "name"];
		pgeofencestore = new Ext.data.Store({
			proxy: new Ext.data.HttpProxy({
				url: "Handler/HandlerSearchPolygonFence",
				method: "POST"
			}),
			reader: new Ext.data.JsonReader({
				fields: pgeofencefields,
				root: "data"
			}),
			autoLoad: true
		});
		alarmData.push(['10010', _AlarmResource_InPolygonFenceAlarm]);
		alarmData.push(['10011', _AlarmResource_OutPolygonFenceAlarm]);
	}

	if (showGBCommand) {
		alarmData.push(['135', _AlarmResource_FatigueDrivingAlarm]);
		alarmData.push(['1001', _AlarmResource_Warning]);
		alarmData.push(['1003', _AlarmResource_GPS_Module_Err]);
		alarmData.push(['1004', _AlarmResource_GPS_Module_Shotted]);
		alarmData.push(['1011', _AlarmResource_LCD_Err]);
		alarmData.push(['1012', _AlarmResource_TTS_Err]);
		alarmData.push(['1013', _AlarmResource_Camera_Err]);
		alarmData.push(['1014', _AlarmResource_DayDriving_Over_Time]);
		alarmData.push(['1015', _AlarmResource_Parking_Over_Time]);
		alarmData.push(['1016', _AlarmResource_RouteDriveTimeNotEnoughOrTooLong]);
		alarmData.push(['1017', _AlarmResource_VSS_Err]);
		alarmData.push(['1018', _AlarmResource_Fuel_Err]);
		alarmData.push(['1019', _AlarmResource_Stolen]);
		alarmData.push(['1020', _AlarmResource_Illegal_ACC]);
		alarmData.push(['1021', _AlarmResource_Illegal_Moving]);
		alarmData.push(['1022', _AlarmResource_Crashed]);
	}

	//load alarmId
	var typestore = new Ext.data.SimpleStore({
		fields: ['id', 'type'],
		data: alarmData
	});

	function addType(id, type) {
		var d = new Object();
		d.id = id;
		d.type = type;
		var record = new Ext.data.Record(d);
		typestore.add(record);
	}

	if (showroutemodel) {
		addType('10001', _AlarmResource_FarAwayRoute);
	}

	var m;
	for (m = 0; m < dymanicalarminfo.length; m++) {
		var ainfo = dymanicalarminfo[m];
		typestore.each(function (record) {
			if (record.get("type") == ainfo.alarmtype) {
				record.set("type", ainfo.expression);
			}
		});
	}

	if (typeof (trackerExtendSensorDefined) != 'undefined') {
		if (trackerExtendSensorDefined) {
			Ext.Ajax.request({
				url: 'HandlerShowTemperatureAlarm',
				method: 'post',
				success: function (v) {
					if (v.responseText == 'True') {
						addType('200', _AlarmResource_HighTemperature);
						addType('201', _AlarmResource_LowTemperature);
						addType('202', _AlarmResource_FuelLow);
						addType('203', _AlarmResource_FuelHigh);
						if (typeof (showFuelDown) != 'undefined') {
							if (showFuelDown) {
								addType('204', _TrackerMain_FuelDown);
							}
						}
					}

				},
				failure: function () {
					Ext.MessageBox.hide();
				}
			});
		}
	}

	if (typeof (defineSetArm) != 'undefined') {
		if (defineSetArm) {
			addType('209', _TrackerMain_Arm);
			addType('210', _TrackerMain_Disarm);
		}
	}

	var trackNameCombo = getTrackerCheckboxCombo(true);

	var fields = ["sssid", "trackername", "alarmtype", "gpstime", "receivedtime", "gpsvalid", "location", "latitude", "longitude", "speed", "alarmexpression", "gpsexpression", { name: "hasgsmlocation", type: "boolean" }, { name: "gsmlatitude", type: "float" }, { name: "gsmlongitude", type: "float" }, { name: "gsmaccuracy", type: "float" }, "RFID", "geofence_alarm_id", "extinfo"];
	var url = "HandlerSearchAlarm";
	if (isOpenExtentFn) {
		fields.push("drivername");
		url = "HandlerSearchAlarmExtention";
	}
	var alarmstore = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy(
		{
			url: url,
			method: "POST",
			timeout: 90000
		}),
		reader: new Ext.data.JsonReader(
		{
			fields: fields,
			root: "data",
			totalProperty: "totalCount"
		})
	});

	alarmstore.addListener('load', function (store, records) {
		var i;
		for (i = 0; i < records.length; i++) {
			var valid = records[i].get("gpsvalid");
			if (valid)
				records[i].set("gpsexpression", _TrackerMain_Valid);
			else
				records[i].set("gpsexpression", _TrackerMain_Invalid);
			if (showmiles) {
				var speedmiles = kilos2miles(records[i].get("speed"));
				records[i].set("speed", speedmiles);
			}
		}
	});

	var alarmTypeCombo = new Ext.ux.form.CheckboxCombo({
		store: typestore,
		mode: 'local',
		displayField: 'type',
		width: 130,
		valueField: 'id',
		enableKeyEvents: true,
		editable: true
	});

	var cmbQuickTimer = new Ext.form.ComboBox({
		editable: false,
		forceSelection: true,
		disableKeyFilter: true,
		typeAhead: false,
		mode: 'local',
		triggerAction: 'all',
		width: 50,
		store: new Ext.data.ArrayStore({
			fields: [{ name: 'val', type: 'integer' }, 'text'],
			data: [[0, _Time_Today], [1, _Time_Yesterday], [2, _Time_7Days], [3, _Time_ThisMonth], [4, _Time_30Days]]
		}),
		displayField: 'text',
		width: 100,
		valueField: 'val'
	});
	cmbQuickTimer.setValue(0);

	cmbQuickTimer.addListener('select', function (obj, record, index) {
		var val = record.get('val');

		var day = new Date();
		var tmpbegintstr = today;
		var tmpendstr = today;
		if (val == 0) {
			tmpbegintstr = today;
			tmpendstr = today;
		}
		else if (val == 1) {
			tmpbegintstr = yestoday;
			tmpendstr = yestoday;
		}
		else if (val == 2) {
			var tmpd = addDays(day, -6);
			tmpbegintstr = tmpd.getFullYear() + '-' + padLeft((tmpd.getMonth() + 1).toString(), '0', 2) + '-' + padLeft(tmpd.getDate().toString(), '0', 2);
			tmpendstr = today;
		}
		else if (val == 3) {
			var tmpd = addDays(day, -6);
			tmpbegintstr = tmpd.getFullYear() + '-' + padLeft((tmpd.getMonth() + 1).toString(), '0', 2) + '-01';
			tmpendstr = today;
		}
		else if (val == 4) {
			var tmpd = addDays(day, -30);
			tmpbegintstr = tmpd.getFullYear() + '-' + padLeft((tmpd.getMonth() + 1).toString(), '0', 2) + '-' + padLeft(tmpd.getDate().toString(), '0', 2);
			tmpendstr = today;
		}
		fromDateEditor.setValue(tmpbegintstr);
		toDateEditor.setValue(tmpendstr);
		fromTimeEditor.setValue("00:00");
		toTimeEditor.setValue("23:59");
	});

	var cmbPageSize = new Ext.form.ComboBox({
		editable: false,
		forceSelection: true,
		disableKeyFilter: true,
		typeAhead: false,
		mode: 'local',
		triggerAction: 'all',
		width: 50,
		store: new Ext.data.ArrayStore({
			fields: [{ name: 'val', type: 'integer' }, { name: 'pagesize', type: 'integer'}],
			data: [[0, 100], [1, 200], [2, 500]]
		}),
		displayField: 'pagesize',
		width: 50,
		valueField: 'val'
	});

	cmbPageSize.setValue(0);

	cmbPageSize.addListener('select', function (obj, record, index) {
		pagesize = record.get('pagesize');
		bar.pageSize = pagesize;
	});


	var bar = new Ext.PagingToolbar({
		pageSize: pagesize,
		store: alarmstore,
		displayInfo: true,
		beforePageText: _Alarm_Page,
		refreshTex: _Alarm_Refresh,
		displayMsg: _Alarm_Displaying,
		emptyMsg: _Alarm_Alarm_emptyMsg
	});

	var fromDateEditor = new Ext.form.DateField({
		renderer: Ext.util.Format.dateRenderer('Y-m-d'),
		format: 'Y-m-d',
		value: today,
		width: 90
	});


	var fromTimeEditor = new Ext.form.TimeField({
		value: '00:00',
		format: 'H:i',
		width: 60
	});

	var toDateEditor = new Ext.form.DateField({
		renderer: Ext.util.Format.dateRenderer('Y-m-d'),
		format: 'Y-m-d',
		value: today,
		width: 90
	});

	var toTimeEditor = new Ext.form.TimeField({
		value: "23:59",
		format: 'H:i',
		width: 60
	});

	var addressCb = new Ext.form.Checkbox({ checked: false });

	var tbar = new Ext.Toolbar({
		items: [
			_Alarm_TrackerName + ':',
			trackNameCombo,
			{
				xtype: 'tbseparator', width: 5
			},
			_Alarm_AlarmType + ':',
			alarmTypeCombo,
			{
				xtype: 'tbseparator', width: 5
			},
		//cmbPageSize,
		//cmbQuickTimer,
			_Alarm_FromTime + ':',
			fromDateEditor,
			{
				xtype: 'tbseparator', width: 5
			},
			fromTimeEditor,
			{
				xtype: 'tbseparator', width: 5
			},
			_Alarm_ToTime + ':',
			toDateEditor,
			{
				xtype: 'tbseparator', width: 5
			},
			toTimeEditor,
			{
				xtype: 'tbseparator', width: 5
			},
			//_TrackerMain_ARP,
			//addressCb, '-', //_Distance_Unit+":", distanceUnitChangeComb, '-',
			{
			tooltip: { text: _TrackerMain_Search, autoHide: true },
			icon: 'Content/images/search16.gif',
			handler: function () {
				alarmstore.load({
					params: {
						fromtime: fromDateEditor.getEl().dom.value + ' ' + fromTimeEditor.getEl().dom.value,
						totime: toDateEditor.getEl().dom.value + ' ' + toTimeEditor.getEl().dom.value,
						alarmId: alarmTypeCombo.getValue(),
						trackName: trackNameCombo.getRawValue(),
						start: 0,
						limit: pagesize
					}
				});
			}
		},
			{
				tooltip: { text: _TrackerMain_ExportToExcel, autoHide: true },
				icon: 'Content/images/excel16.gif',
				handler: function () {
					if (!Ext.fly('alarmexcel')) {
						var frm = document.createElement('form');
						frm.id = 'alarmexcel';
						frm.name = id;
						frm.style.display = 'block';
						document.body.appendChild(frm);
					}
					var requestaddress = false;
					requestaddress= addressCb.getValue();
					if (typeof (pcsaddress) != 'undefined') {
						requestaddress = pcsaddress && addressCb.getValue();
					}
					Ext.Ajax.request({
						url: 'HandlerExcel',
						form: Ext.fly('alarmexcel'),
						method: 'POST',
						params: {
							exceltype: 'alarm',
							start: 0,
							limit: 60000,
							trackName: trackNameCombo.getRawValue(),
							alarmId: alarmTypeCombo.getValue(),
							fromtime: fromDateEditor.getEl().dom.value + ' ' + fromTimeEditor.getEl().dom.value,
							totime: toDateEditor.getEl().dom.value + ' ' + toTimeEditor.getEl().dom.value,
							requestaddress: requestaddress ? "1" : "0"
						},
						isUpload: true
					});
				}
			}
			/*
			, {
				tooltip: { text: _TrackerMain_ExportToKML, autoHide: true },
				icon: 'Content/images/kml.gif',
				handler: function () {
					if (!Ext.fly('alarmkml')) {
						var frm = document.createElement('form');
						frm.id = 'alarmkml';
						frm.name = id;
						frm.style.display = 'none';
						document.body.appendChild(frm);
					}
					Ext.Ajax.request({
						url: 'HandlerAlarmKML',
						form: Ext.fly('alarmkml'),
						method: 'POST',
						params: {
							exceltype: 'alarm',
							start: 0,
							limit: 60000,
							trackName: trackNameCombo.getRawValue(),
							alarmId: alarmTypeCombo.getValue(),
							fromtime: fromDateEditor.getEl().dom.value + ' ' + fromTimeEditor.getEl().dom.value,
							totime: toDateEditor.getEl().dom.value + ' ' + toTimeEditor.getEl().dom.value
						},
						isUpload: true
					});

				}
			}
			*/
		]
	});
	var columns = new Array();
	var speedexp = showmiles ? _Alarm_Header_Speed + "(" + _TrackerMain_MPH + ")" : _Alarm_Header_Speed;
	if (isOpenExtentFn) {
		columns = [{ header: _RFIDResource_DriverName, width: 75, sortable: true, menuDisabled: true, dataIndex: 'drivername' },
					{ header: _Alarm_Header_Name, width: 75, sortable: true, menuDisabled: true, dataIndex: 'trackername' },
					{ header: _Alarm_Header_AlarmType, width: 250, sortable: true, menuDisabled: true, dataIndex: 'alarmexpression',
						renderer: function (value, a, record) {
							if (showPolygonFence) {
								var alarmid = record.get('alarmtype');
								var s = getAlarmStringFromAlarmTypeExtend(alarmid, record.get('sssid'));
								var count = pgeofencestore.getCount();
								var geoname = "";
								for (var i = 0; i < count; i++) {
									if (pgeofencestore.getAt(i).get('polygon_geofence_id') == record.get('geofence_alarm_id')) {
										geoname = pgeofencestore.getAt(i).get('name');
										break;
									}
								}

								if (alarmid == "10010") {
									return _TxtIn + '(' + geoname + ')';
								}
								else if (alarmid == "10011") {
									return _TxtOut + '(' + geoname + ')';
								}
								else {
									return s;
								}
							}
							else
								return value;
						}
					},
					{ header: _Alarm_Header_GPSTime, width: 95, sortable: true, menuDisabled: true, dataIndex: 'gpstime' },
					{ header: _Alarm_Header_RecTime, width: 95, sortable: true, menuDisabled: true, dataIndex: 'receivedtime' },
					{ header: _Alarm_Header_GpsVaild, width: 65, sortable: true, menuDisabled: true, dataIndex: 'gpsexpression' },
					{ header: _Alarm_Header_Location, width: 220, sortable: true, menuDisabled: true, dataIndex: 'location' },
					{ header: _Alarm_Header_Latitude, width: 85, sortable: true, menuDisabled: true, dataIndex: 'latitude' },
					{ header: _Alarm_Header_Longitude, width: 85, sortable: true, menuDisabled: true, dataIndex: 'longitude' },
					{ header: speedexp, width: 85, sortable: true, menuDisabled: true, dataIndex: 'speed' }
						  ]
	}
				else {
		columns = [
					{ header: _Alarm_Header_Name, width: 75, sortable: true, menuDisabled: true, dataIndex: 'trackername' },
					{ header: _Alarm_Header_AlarmType, width: 250, sortable: true, menuDisabled: true, dataIndex: 'alarmexpression',
						renderer: function (value, a, record) {
							if (showPolygonFence) {
								var alarmid = record.get('alarmtype');
								var s = getAlarmStringFromAlarmTypeExtend(alarmid, record.get('sssid'));
								var count = pgeofencestore.getCount();
								var geoname = "";
								for (var i = 0; i < count; i++) {
									if (pgeofencestore.getAt(i).get('polygon_geofence_id') == record.get('geofence_alarm_id')) {
										geoname = pgeofencestore.getAt(i).get('name');
										break;
									}
								}

								if (alarmid == "10010") {
									return _TxtIn + '(' + geoname + ')';
								}
								else if (alarmid == "10011") {
									return _TxtOut + '(' + geoname + ')';
								}
								else {
									return s;
								}
							}
							else
								return value;
						}

					},
					{ header: _Alarm_Header_GPSTime, width: 95, sortable: true, menuDisabled: true, dataIndex: 'gpstime' },
					{ header: _Alarm_Header_RecTime, width: 95, sortable: true, menuDisabled: true, dataIndex: 'receivedtime' },
					{ header: _Alarm_Header_GpsVaild, width: 65, sortable: true, menuDisabled: true, dataIndex: 'gpsexpression' },
					{ header: _Alarm_Header_Location, width: 220, sortable: true, menuDisabled: true, dataIndex: 'location' },
					{ header: _Alarm_Header_Latitude, width: 85, sortable: true, menuDisabled: true, dataIndex: 'latitude' },
					{ header: _Alarm_Header_Longitude, width: 85, sortable: true, menuDisabled: true, dataIndex: 'longitude' },
					{ header: speedexp, width: 85, sortable: true, menuDisabled: true, dataIndex: 'speed' }
		//  { header: _TrackerMain_Satellites, width: 60, sortable: true, menuDisabled: true, dataIndex: 'satellites' },
		//{ header: _TrackerMain_GSMSignal, width: 60, sortable: true, menuDisabled: true, dataIndex: 'gsmsignal' }
				]
	}
	var grdAlarm = new Ext.grid.GridPanel({
		store: alarmstore,
		loadMask: true,
		columns: columns,
		width: 1100,
		height: 450,
		title: _Alarm_AlarmGrid
	});

	grdAlarm.addListener('render', function (grid) {
		var store = grid.getStore();  // Capture the Store.	
		var view = grid.getView();	// Capture the GridView.
		grid.tip = new Ext.ToolTip({
			target: view.mainBody,	// The overall target element.
			//delegate: '.x-grid3-row', // Each grid row causes its own seperate show and hide.	
			delegate: '.x-grid3-cell', // Each grid cell causes its own seperate show and hide.	
			trackMouse: true,		 // Moving within the row should not hide the tip.	
			renderTo: document.body,  // Render immediately so that tip.body can be referenced prior to the first show.	
			listeners: {			  // Change content dynamically depending on which element triggered the show.	
				beforeshow: function updateTipBody(tip) {
					var rowIndex = view.findRowIndex(tip.triggerElement);
					var cellIndex = view.findCellIndex(tip.triggerElement);
					if (cellIndex == 1 || cellIndex == 5) {
						var cell = view.getCell(rowIndex, cellIndex);
						if (cell.innerText.length > 0) {
							tip.body.dom.innerHTML = cell.innerText;
							return true;
						}
						else
							return false;
					}
					else {
						return false;
					}
				}
			}
		});
	});


	grdAlarm.addListener('rowdblclick', function (obj, index) {
		var record = grdAlarm.getStore().getAt(index);
		var name = record.get("trackername");
		var gpsvalid = parseInt(record.get("gpsvalid"));
		var longitude = parseFloat(record.get("longitude"));
		var latitude = parseFloat(record.get("latitude"));
		var direction = parseInt(record.get("direction"));
		var speed = parseFloat(record.get("speed"));
		var altitude = parseInt(record.get("altitude"));
		var gpstime = record.get("gpstime");
		var receivedtime = record.get("receivedtime");
		var location = record.get("location");
		var alarm = record.get("alarmexpression");
		var hasgsmlocation = record.get("hasgsmlocation");
		var gsm = null;
		if (hasgsmlocation) {
			var gsmlatitude = record.get("gsmlatitude");
			var gsmlongitude = record.get("gsmlongitude");
			var gsmaccuracy = record.get("gsmaccuracy");
			var gsm = null;
			if (hasgsmlocation) {
				gsm = new GSMInfo(gsmlatitude, gsmlongitude, 0, gsmaccuracy, "");
			}
		}
		var alarminfo = new TrackerInfo("", name, "", gpsvalid, longitude, latitude, gpstime, receivedtime, direction, speed, altitude, "", location, alarm, gsm);

		/*
		var win = createAlarmMapWindow(_TrackerMain_AlarmPoint + '(' + record.get('trackername') + ',' + record.get('gpstime') + ')');
		win.show(); // 显示出来
		nextwindowx += 20;
		nextwindowy += 20;
		var rmap = createMap(win.getMap(), true, null, gmapurl);
		rmap.drawAlarmPoint(alarminfo);
		*/
		var newMap = Sample.ExtGMap.initpos(latitude,longitude);

		var gmapwindow = new Ext.Window({
			title: _TrackerMain_AlarmPoint + '(' + record.get('trackername') + ',' + record.get('gpstime') + ')',
			closable: true,
			width: 500,
			height: 450,
			minimizable: false,
			items: [newMap]
		});
		gmapwindow.show();
	});

	var alarmwindow = new Ext.Window({
		title: _Alarm_AlarmWindow,
		layout: 'fit',
		height: 520,
		width: 1230,
		iconCls: 'report-alarm',
		items: grdAlarm,
		tbar: tbar,
		bbar: bar,
		minimizable: true,
		constrain: true,
		listeners: {
			'minimize': function () {
				addTaskButtonForWindow(alarmwindow);
			}
		}
	});

	alarmstore.on('beforeload', function (store) {
		alarmstore.baseParams = {
			start: 'start', limit: 'limit', trackName: trackNameCombo.getRawValue(), alarmId: alarmTypeCombo.getValue(), fromtime: fromDateEditor.getEl().dom.value + ' ' + fromTimeEditor.getEl().dom.value, totime: toDateEditor.getEl().dom.value + ' ' + toTimeEditor.getEl().dom.value
		}
	})

	var geoInterval;
	alarmstore.on('load', function (store) {
		alarmstore.each(function (record) {
			if (record.get("alarmtype") == 125)
				record.set("alarmexpression", getAlarmStringFromAlarmType(record.get("alarmtype")) + "(" + record.get("RFID") + ")");
			else if (record.get("alarmtype") == 112 || record.get("alarmtype") == 113)
				record.set("alarmexpression", getAlarmStringFromAlarmType(record.get("alarmtype")) + "(" + record.get("geofence_alarm_id") + ")");
			else
				record.set("alarmexpression", getAlarmStringFromAlarmType(record.get("alarmtype")));

			record.set("location", record.get("latitude") + "," + record.get("longitude"));

			if (record.get("alarmtype") == 200 || record.get("alarmtype") == 201 || record.get("alarmtype") == 202 || record.get("alarmtype") == 203 || record.get("alarmtype") == 204) {
				//温度报警
				if (record.get("extinfo") != "") {
					record.set("alarmexpression", getAlarmStringFromAlarmType(record.get("alarmtype")) + "(" + record.get("extinfo") + ")");
				}
			}

		});

		if (addressCb.getValue() == true) {

			if (!Ext.isEmpty(geoInterval))
				window.clearInterval(geoInterval);
			var i = 0;
			var count = alarmstore.getCount(), recycleTimes = 0;
			if (count > 0) {
				geoInterval = window.setInterval(function () {
					if (recycleTimes >= 10) {
						i++;
						recycleTimes = 0;
					}
					if (i == count) {
						window.clearInterval(geoInterval);
						return;
					}
					else {
						var record = store.getAt(i);
						imap.geoCoder(String(record.data.latitude), String(record.data.longitude),
								function (address, index) {
									if (address == "") {
										recycleTimes++;
										return;
									}
									record.set("location", address);
									i += index;
								});
					}
				}, 1000);
			}
		}
	});
	alarmwindow.show();
};